<template>
	<view class="container">
		<view class="formItem">
			<view>操作人员</view>
			<view>
				<input class="uni-input" v-model="operator" />
			</view>
		</view>
		<view class="formItem">
			<view>解除时间</view>
			<view>
				<e-picker-plus ref='picker' @confirm="getDate" mode='YMDhms'>{{relieveTime}}</e-picker-plus>
			</view>
		</view>
		
		<button class="confirm_btn" type="primary" @click="relieveAlarmFn">提交</button>

	</view>
</template>

<script>
	import {mapActions, mapState} from 'vuex'
	import {mixin} from '../../../common/mixins.js'
export default {
	mixins:[mixin],
	data() {
		return {
			equipCode:'',
			alarmId:'',
			relieveTime:'',
			operator:''
		};
	},
	computed: {
		...mapState({
			//这里可以通过这种方式引用相应模块的state数据，其中user是模块名。在代码的其他部分可以使用this.userInfo访问数据
			userInfo: ({user}) => user.userInfo,
		}),
	},
	watch:{
		userInfo:{
			handler(newVal){
				this.operator = newVal.nickName
			},
			deep:true,
			immediate:true
		}
	},
	onLoad(option) {
		if(option.id){
			this.alarmId = option.id
		}else if(option.equipCode){
			this.equipCode = option.equipCode
		}
		
		this.$refs.picker._setValue()
		this.relieveTime = this.$refs.picker.showDateTime
	},
	methods: {
		relieveAlarmFn(){
			if(!this.operator || !this.operator.trim()){
				uni.showToast({
					icon:'none',
					title:'请输入操作人员名字'
				})
				return
			}
			if(this.alarmId){
				this.$api.relieveAlarm({
					relieveTime:this.relieveTime,
					alarmId:this.alarmId,
					operator:this.operator
				}).then(res => {
					if(res.data.code == '00000'){
						uni.showToast({
							icon:'none',
							title:res.data.message,
							complete() {
								setTimeout(()=>{
									uni.navigateBack()
								},1500)
							}
						})
						return
					}
					uni.$emit('relieveAlarmSuccess')
					uni.showToast({
						title:'解除成功',
						duration:1500,
						success() {
							setTimeout(()=>{
								uni.navigateBack()
							},1500)
						}
					})
					
				})
				
			}else{
				
				this.$api.relieveAbnormal({
					relieveTime:this.relieveTime,
					equipCode:this.equipCode,
					operator:this.operator
				}).then(res => {
					if(res.data.code == '00000'){
						uni.showToast({
							icon:'none',
							title:res.data.message,
							complete() {
								setTimeout(()=>{
									uni.navigateBack()
								},1500)
							}
						})
						return
					}
					uni.$emit('relieveAlarmEquipSuccess')
					uni.showToast({
						title:'解除成功',
						duration:1500,
						success() {
							setTimeout(()=>{
								uni.navigateBack()
							},1500)
						}
					})
					
				})
			}
	
		},
		getDate(e) {
			this.relieveTime = e.result
		}
	}
};
</script>

<style lang="scss" scoped>
.container{
	background: #fff;
	height: 100vh;
}
.formItem{
	margin: 60rpx 60rpx 0;
	border-bottom: 2rpx solid #c5c5c5;
	&>view{
		height: 40rpx;
		line-height: 40rpx;
		margin-bottom: 30rpx;
		font-size: 32rpx;
	}
}
.confirm_btn{
	position: absolute;
	left: 50rpx;
	right: 50rpx;
	bottom: 60rpx;
	background: #428ee4;
	height: 90rpx;
	line-height: 90rpx;
	font-size: 32rpx;
	width: calc(100% - 100rpx);
}
</style>
